package com.controller.library;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import javax.servlet.http.*;
import com.action.library.SGetCourseAction;
import com.bean.library.Course;
import com.bean.library.Paper;

public class CourseSelectServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request,HttpServletResponse response){
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		String testType = request.getParameter("test_type");
		String courseId = request.getParameter("select_course");
		/*************通过课程去获取试卷信息***********/
		SGetCourseAction sGetCourseAction = new SGetCourseAction();
		Course course = sGetCourseAction.getCourse(courseId);
		request.getSession().setAttribute("selectedCourse", course);
		response.setContentType("text/html");
		
		if(testType.equals("exam")){
			try {
				response.sendRedirect("/Exam1/student/page/exam.jsp?" + request.getQueryString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		else if(testType.equals("practice")){
			//获取试卷简要信息列表
			ArrayList<Paper> partialPaperList = course.getBriefPaperList(0, 5);
			request.getSession().setAttribute("partialPaperList", partialPaperList);
			try {
				response.sendRedirect("/Exam1/student/page/simulate.jsp?" + request.getQueryString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		else if(testType.equals("free")){
			try {
				response.sendRedirect("/Exam1/student/page/freeAnswer.jsp?" + request.getQueryString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}

